# Maintainer: Wu Zhenyu <wuzy01@qq.com>

_realname=scrcpy
pkgbase="mingw-w64-${_realname}"
pkgname="$MINGW_PACKAGE_PREFIX-${_realname}"
pkgver=3.2
pkgrel=1
pkgdesc='Display and control your Android device (mingw-w64)'
arch=(any)
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/Genymobile/scrcpy'
msys2_references=(
  'archlinux: scrcpy'
)
license=('spdx:Apache-2.0')
depends=(
  "$MINGW_PACKAGE_PREFIX-android-tools"
  "$MINGW_PACKAGE_PREFIX-ffmpeg"
  "$MINGW_PACKAGE_PREFIX-SDL2"
  "$MINGW_PACKAGE_PREFIX-libusb"
)
makedepends=(
  "$MINGW_PACKAGE_PREFIX-cc"
  "$MINGW_PACKAGE_PREFIX-meson"
  "$MINGW_PACKAGE_PREFIX-pkgconf"
)
source=("$url/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "$url/releases/download/v${pkgver}/${_realname}-server-v${pkgver}"
        0001-Help-scrcpy-find-the-server-and-icon-file.patch)
sha256sums=('9902a3afd75f9a5da64898ac06ffaf77065dd713a58f47a408630b98f03ba9ce'
            'b920e0ea01936bf2482f4ba2fa985c22c13c621999e3d33b45baa5acfc1ea3d0'
            'ab91eeea32b026505f51a1cad3c4eb45f28ba1d8a8f8ca92a4f55063ce9a8152')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p1 -i "${srcdir}/0001-Help-scrcpy-find-the-server-and-icon-file.patch"
}

build() {
  mkdir -p "build-${MSYSTEM}" && cd "build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix="${MINGW_PREFIX}" \
    --buildtype release \
    -Dprebuilt_server="../${_realname}-server-v${pkgver}" \
    ../"${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/meson.exe install --destdir="${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}"/LICENSE -t \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
